package com.bootdo.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.common.controller.BaseController;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.system.domain.ScanRecord;
import com.bootdo.system.service.ScanRecordService;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RequestMapping("/sys/scanRecord")
@Controller
@Api(value = "/sys/scanRecord", description = "商户二维扫描记录操作接口")
public class ScanRecordController extends BaseController {
	
	@Autowired
	ScanRecordService service;


	@ApiOperation(value="商户二维码扫描记录查询", notes="根据条件查询商户二维码扫描记录", response=String.class)
	@ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "商户二维码扫描记录id", required = false,paramType="query", dataType = "Long"),
        @ApiImplicitParam(name = "customerId", value = "商户id", required = false,paramType="query", dataType = "String"),
        @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true,paramType="query", dataType = "Integer"),
        @ApiImplicitParam(name = "pageNum", value = "当前页数", required = true,paramType="query", dataType = "Integer")
	})
	@GetMapping("/list")
	@ResponseBody
	R list(@RequestParam Map<String,Object> param) throws Exception{
		Query query = new Query(param);
		List<ScanRecord> address = service.list(query);
		PageInfo<ScanRecord> pageInfo = new PageInfo<ScanRecord>(address);
		int total = (int)pageInfo.getTotal();
		PageUtils pageUtil = new PageUtils(address, total);
		return new R("list",pageUtil);
	}

	@ApiOperation(value="商户二维码扫描记录详情", notes="根据条件查询商户二维码扫描记录", response=String.class)
	@ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "商户二维码扫描记录id", required = true,paramType="query", dataType = "Long"),
	})
	@GetMapping("/edit")
	@ResponseBody
	R edit(Long id)  throws Exception{
		return new R("obj",service.get(id));
	}

	
	@ApiOperation(value="商户二维码扫描次数查询", notes="根据条件查询单个商户二维码扫描次数", response=String.class)
	@ApiImplicitParams({
        @ApiImplicitParam(name = "customerId", value = "商户id", required = true,paramType="query", dataType = "Long"),
	})
	@GetMapping("/getTotalByCustomerId")
	@ResponseBody
	R getTotalByCustomerId(Long customerId)  throws Exception{
		return new R("total",service.getTotalByCustomerId(customerId));
	}

	
	@ApiOperation(value="商户二维码扫描记录保存", notes="保存商户二维码扫描记录", response=String.class)
	@PostMapping("/save")
	@ResponseBody
	R save(@RequestBody ScanRecord baby) throws Exception {
		if (service.save(baby) > 0) {
			return R.saveOk(baby.getId().toString());
		} else {
			return R.error(1, "保存失败");
		}
	}

	@ApiOperation(value="商户二维码扫描统计查询", notes="根据条件查询商户二维码扫描次数", response=String.class)
	@ApiImplicitParams({
        @ApiImplicitParam(name = "customerId", value = "商户id", required = false,paramType="query", dataType = "String"),
        @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true,paramType="query", dataType = "Integer"),
        @ApiImplicitParam(name = "pageNum", value = "当前页数", required = true,paramType="query", dataType = "Integer")
	})
	@GetMapping("/countList")
	@ResponseBody
	R countList(@RequestParam Map<String,Object> param) throws Exception{
		Query query = new Query(param);
		List<ScanRecord> address = service.countList(query);
		PageInfo<ScanRecord> pageInfo = new PageInfo<ScanRecord>(address);
		int total = (int)pageInfo.getTotal();
		PageUtils pageUtil = new PageUtils(address, total);
		return new R("list",pageUtil);
	}
	
	
}
